home *** CD-ROM | disk | FTP | other *** search
- #include "dwarf_incl.h"
- #include "dwarf_die_deliv.h"
-
- int
- dwarf_hasform (
- Dwarf_Attribute attr,
- Dwarf_Half form,
- Dwarf_Bool *return_bool,
- Dwarf_Error *error
- )
- {
- if (attr == NULL) {
- _dwarf_error(NULL,error,DW_DLE_ATTR_NULL);
- return(DW_DLV_ERROR);
- }
-
- if (attr->ar_cu_context == NULL) {
- _dwarf_error(NULL,error,DW_DLE_ATTR_NO_CU_CONTEXT);
- return(DW_DLV_ERROR);
- }
-
- if (attr->ar_cu_context->cc_dbg == NULL) {
- _dwarf_error(NULL,error,DW_DLE_ATTR_DBG_NULL);
- return(DW_DLV_ERROR);
- }
-
- *return_bool = (attr->ar_attribute_form == form);
- return DW_DLV_OK;
- }
-
-
- int
- dwarf_whatform (
- Dwarf_Attribute attr,
- Dwarf_Half * return_form,
- Dwarf_Error *error
- )
- {
- if (attr == NULL) {
- _dwarf_error(NULL,error,DW_DLE_ATTR_NULL);
- return(DW_DLV_ERROR);
- }
-
- if (attr->ar_cu_context == NULL) {
- _dwarf_error(NULL,error,DW_DLE_ATTR_NO_CU_CONTEXT);
- return(DW_DLV_ERROR);
- }
-
- if (attr->ar_cu_context->cc_dbg == NULL) {
- _dwarf_error(NULL,error,DW_DLE_ATTR_DBG_NULL);
- return(DW_DLV_ERROR);
- }
-
- *return_form = attr->ar_attribute_form;
- return(DW_DLV_OK);
- }
-
-
- /*
- This function is analogous to dwarf_whatform.
- It returns the attribute in attr instead of
- the form.
- */
- int
- dwarf_whatattr (
- Dwarf_Attribute attr,
- Dwarf_Half * return_attr,
- Dwarf_Error *error
- )
- {
- if (attr == NULL) {
- _dwarf_error(NULL,error,DW_DLE_ATTR_NULL);
- return(DW_DLV_ERROR);
- }
-
- if (attr->ar_cu_context == NULL) {
- _dwarf_error(NULL,error,DW_DLE_ATTR_NO_CU_CONTEXT);
- return(DW_DLV_ERROR);
- }
-
- if (attr->ar_cu_context->cc_dbg == NULL) {
- _dwarf_error(NULL,error,DW_DLE_ATTR_DBG_NULL);
- return(DW_DLV_ERROR);
- }
-
- *return_attr = (attr->ar_attribute);
- return DW_DLV_OK;
- }
-
-
- /*
- DW_FORM_ref_addr is considered an incorrect form
- for this call because this function returns an
- offset thru the pointer ,
- and DW_FORM_ref_addr returns an address.
- */
- int
- dwarf_formref (
- Dwarf_Attribute attr,
- Dwarf_Off * ret_offset,
- Dwarf_Error *error
- )
- {
- Dwarf_Debug dbg;
- Dwarf_Unsigned offset;
-
- if (attr == NULL) {
- _dwarf_error(NULL,error,DW_DLE_ATTR_NULL);
- return(DW_DLV_ERROR);
- }
-
- if (attr->ar_cu_context == NULL) {
- _dwarf_error(NULL,error,DW_DLE_ATTR_NO_CU_CONTEXT);
- return(DW_DLV_ERROR);
- }
-
- if (attr->ar_cu_context->cc_dbg == NULL) {
- _dwarf_error(NULL,error,DW_DLE_ATTR_DBG_NULL);
- return(DW_DLV_ERROR);
- }
- dbg = attr->ar_cu_context->cc_dbg;
-
- switch (attr->ar_attribute_form) {
-
- case DW_FORM_ref1 :
- offset = *(Dwarf_Small *)attr->ar_debug_info_ptr;
- break;
-
- case DW_FORM_ref2 :
- READ_UNALIGNED(offset, attr->ar_debug_info_ptr, sizeof(Dwarf_Half));
- break;
-
- case DW_FORM_ref4 :
- READ_UNALIGNED(offset, attr->ar_debug_info_ptr, sizeof(Dwarf_Word));
- break;
-
- case DW_FORM_ref8 :
- READ_UNALIGNED(offset, attr->ar_debug_info_ptr,
- sizeof(Dwarf_Unsigned));
- break;
-
- case DW_FORM_ref_udata :
- offset = _dwarf_decode_u_leb128(attr->ar_debug_info_ptr,NULL);
- break;
-
- default :
- _dwarf_error(dbg,error,DW_DLE_BAD_REF_FORM);
- return(DW_DLV_ERROR);
- }
-
- /* Check that offset is within current cu portion of .debug_info. */
- if (offset >= attr->ar_cu_context->cc_length + dbg->de_length_size) {
- _dwarf_error(dbg, error, DW_DLE_ATTR_FORM_OFFSET_BAD);
- return(DW_DLV_ERROR);
- }
-
- *ret_offset = (offset);
- return DW_DLV_OK;
- }
-
-
- int
- dwarf_formaddr (
- Dwarf_Attribute attr,
- Dwarf_Addr * return_addr,
- Dwarf_Error *error
- )
- {
- Dwarf_Debug dbg;
- Dwarf_Addr ret_addr;
-
- if (attr == NULL) {
- _dwarf_error(NULL,error,DW_DLE_ATTR_NULL);
- return(DW_DLV_ERROR);
- }
-
- if (attr->ar_cu_context == NULL) {
- _dwarf_error(NULL,error,DW_DLE_ATTR_NO_CU_CONTEXT);
- return(DW_DLV_ERROR);
- }
-
- if (attr->ar_cu_context->cc_dbg == NULL) {
- _dwarf_error(NULL,error,DW_DLE_ATTR_DBG_NULL);
- return(DW_DLV_ERROR);
- }
- dbg = attr->ar_cu_context->cc_dbg;
-
- if (attr->ar_attribute_form == DW_FORM_addr ||
- attr->ar_attribute_form == DW_FORM_ref_addr) {
- READ_UNALIGNED(ret_addr, attr->ar_debug_info_ptr, dbg->de_length_size);
- *return_addr = ret_addr;
- return(DW_DLV_OK);
- }
-
- _dwarf_error(dbg, error, DW_DLE_ATTR_FORM_BAD);
- return(DW_DLV_ERROR);
- }
-
-
- int
- dwarf_formflag (
- Dwarf_Attribute attr,
- Dwarf_Bool * ret_bool,
- Dwarf_Error *error
- )
- {
- if (attr == NULL) {
- _dwarf_error(NULL,error,DW_DLE_ATTR_NULL);
- return(DW_DLV_ERROR);
- }
-
- if (attr->ar_cu_context == NULL) {
- _dwarf_error(NULL,error,DW_DLE_ATTR_NO_CU_CONTEXT);
- return(DW_DLV_ERROR);
- }
-
- if (attr->ar_cu_context->cc_dbg == NULL) {
- _dwarf_error(NULL,error,DW_DLE_ATTR_DBG_NULL);
- return(DW_DLV_ERROR);
- }
-
- if (attr->ar_attribute_form == DW_FORM_flag) {
- *ret_bool = (*(Dwarf_Small *)attr->ar_debug_info_ptr != 0);
- return(DW_DLV_OK);
- }
- _dwarf_error(attr->ar_cu_context->cc_dbg,error,DW_DLE_ATTR_FORM_BAD);
- return(DW_DLV_ERROR);
- }
-
-
- int
- dwarf_formudata (
- Dwarf_Attribute attr,
- Dwarf_Unsigned *return_uval,
- Dwarf_Error *error
- )
- {
- Dwarf_Unsigned ret_value;
-
- if (attr == NULL) {
- _dwarf_error(NULL,error,DW_DLE_ATTR_NULL);
- return(DW_DLV_ERROR);
- }
-
-
- if (attr->ar_cu_context == NULL) {
- _dwarf_error(NULL,error,DW_DLE_ATTR_NO_CU_CONTEXT);
- return(DW_DLV_ERROR);
- }
-
- if (attr->ar_cu_context->cc_dbg == NULL) {
- _dwarf_error(NULL,error,DW_DLE_ATTR_DBG_NULL);
- return(DW_DLV_ERROR);
- }
-
- switch (attr->ar_attribute_form) {
-
- case DW_FORM_data1 :
- READ_UNALIGNED(ret_value, attr->ar_debug_info_ptr,
- sizeof(Dwarf_Small));
- *return_uval = ret_value;
- return DW_DLV_OK;
-
- case DW_FORM_data2 : {
- READ_UNALIGNED(ret_value, attr->ar_debug_info_ptr,
- sizeof(Dwarf_Half));
- *return_uval = ret_value;
- return DW_DLV_OK;
- }
-
- case DW_FORM_data4 : {
- READ_UNALIGNED(ret_value, attr->ar_debug_info_ptr,
- sizeof(Dwarf_Word));
- *return_uval = ret_value;
- return DW_DLV_OK;
- }
-
- case DW_FORM_data8 : {
- READ_UNALIGNED(ret_value, attr->ar_debug_info_ptr,
- sizeof(Dwarf_Unsigned));
- *return_uval = ret_value;
- return DW_DLV_OK;
- }
-
- case DW_FORM_udata :
- ret_value = (_dwarf_decode_u_leb128(attr->ar_debug_info_ptr,NULL));
- *return_uval = ret_value;
- return DW_DLV_OK;
-
- default :
- break;
- }
- _dwarf_error(attr->ar_cu_context->cc_dbg,error,
- DW_DLE_ATTR_FORM_BAD);
- return(DW_DLV_ERROR);
- }
-
-
- int
- dwarf_formsdata (
- Dwarf_Attribute attr,
- Dwarf_Signed * return_sval,
- Dwarf_Error *error
- )
- {
- Dwarf_Signed ret_value;
-
- if (attr == NULL) {
- _dwarf_error(NULL,error,DW_DLE_ATTR_NULL);
- return(DW_DLV_ERROR);
- }
-
- if (attr->ar_cu_context == NULL) {
- _dwarf_error(NULL,error,DW_DLE_ATTR_NO_CU_CONTEXT);
- return(DW_DLV_ERROR);
- }
-
- if (attr->ar_cu_context->cc_dbg == NULL) {
- _dwarf_error(NULL,error,DW_DLE_ATTR_DBG_NULL);
- return(DW_DLV_ERROR);
- }
-
- switch (attr->ar_attribute_form) {
-
- case DW_FORM_data1 :
- *return_sval = (*(Dwarf_Sbyte *)attr->ar_debug_info_ptr);
- return DW_DLV_OK;
-
- case DW_FORM_data2 : {
- READ_UNALIGNED(ret_value, attr->ar_debug_info_ptr,
- sizeof(Dwarf_Shalf));
- *return_sval = ret_value;
- return DW_DLV_OK;
-
- }
-
- case DW_FORM_data4 : {
- READ_UNALIGNED(ret_value, attr->ar_debug_info_ptr,
- sizeof(Dwarf_Sword));
- *return_sval = ret_value;
- return DW_DLV_OK;
- }
-
- case DW_FORM_data8 : {
- READ_UNALIGNED(ret_value, attr->ar_debug_info_ptr,
- sizeof(Dwarf_Signed));
- *return_sval = ret_value;
- return DW_DLV_OK;
- }
-
- case DW_FORM_sdata :
- ret_value = (_dwarf_decode_s_leb128(attr->ar_debug_info_ptr,NULL));
- *return_sval = ret_value;
- return DW_DLV_OK;
-
- default :
- break;
- }
- _dwarf_error(attr->ar_cu_context->cc_dbg,error,
- DW_DLE_ATTR_FORM_BAD);
- return(DW_DLV_ERROR);
- }
-
-
- int
- dwarf_formblock (
- Dwarf_Attribute attr,
- Dwarf_Block ** return_block,
- Dwarf_Error *error
- )
- {
- Dwarf_CU_Context cu_context;
- Dwarf_Debug dbg;
- Dwarf_Unsigned length;
- Dwarf_Small *data;
- Dwarf_Word leb128_length;
- Dwarf_Block *ret_block;
-
- if (attr == NULL) {
- _dwarf_error(NULL,error,DW_DLE_ATTR_NULL);
- return(DW_DLV_ERROR);
- }
-
- if (attr->ar_cu_context == NULL) {
- _dwarf_error(NULL,error,DW_DLE_ATTR_NO_CU_CONTEXT);
- return(DW_DLV_ERROR);
- }
- cu_context = attr->ar_cu_context;
-
- if (cu_context->cc_dbg == NULL) {
- _dwarf_error(NULL,error,DW_DLE_ATTR_DBG_NULL);
- return(DW_DLV_ERROR);
- }
- dbg = cu_context->cc_dbg;
-
- switch (attr->ar_attribute_form) {
-
- case DW_FORM_block1 :
- length = *(Dwarf_Small *)attr->ar_debug_info_ptr;
- data = attr->ar_debug_info_ptr + sizeof(Dwarf_Small);
- break;
-
- case DW_FORM_block2 :
- READ_UNALIGNED(length, attr->ar_debug_info_ptr, sizeof(Dwarf_Half));
- data = attr->ar_debug_info_ptr + sizeof(Dwarf_Half);
- break;
-
- case DW_FORM_block4 :
- READ_UNALIGNED(length, attr->ar_debug_info_ptr, sizeof(Dwarf_Word));
- data = attr->ar_debug_info_ptr + sizeof(Dwarf_Word);
- break;
-
- case DW_FORM_block :
- length = _dwarf_decode_u_leb128(attr->ar_debug_info_ptr,
- &leb128_length);
- data = attr->ar_debug_info_ptr + leb128_length;
- break;
-
- default :
- _dwarf_error(cu_context->cc_dbg,error,DW_DLE_ATTR_FORM_BAD);
- return(DW_DLV_ERROR);
- break;
- }
-
- /* Check that block lies within current cu in .debug_info. */
- if (attr->ar_debug_info_ptr + length >=
- dbg->de_debug_info + cu_context->cc_debug_info_offset +
- cu_context->cc_length + dbg->de_length_size) {
- _dwarf_error(dbg, error, DW_DLE_ATTR_FORM_SIZE_BAD);
- return(DW_DLV_ERROR);
- }
-
- ret_block = (Dwarf_Block *)_dwarf_get_alloc(dbg, DW_DLA_BLOCK, 1);
- if (ret_block == NULL) {
- _dwarf_error(dbg,error,DW_DLE_ALLOC_FAIL);
- return(DW_DLV_ERROR);
- }
-
- ret_block->bl_len = length;
- ret_block->bl_data = (Dwarf_Ptr)data;
-
- *return_block = ret_block;
- return(DW_DLV_OK);
- }
-
-
- int
- dwarf_formstring (
- Dwarf_Attribute attr,
- char ** return_str,
- Dwarf_Error *error
- )
- {
- Dwarf_CU_Context cu_context;
- Dwarf_Debug dbg;
- Dwarf_Unsigned offset;
-
- if (attr == NULL) {
- _dwarf_error(NULL,error,DW_DLE_ATTR_NULL);
- return(DW_DLV_ERROR);
- }
-
- if (attr->ar_cu_context == NULL) {
- _dwarf_error(NULL,error,DW_DLE_ATTR_NO_CU_CONTEXT);
- return(DW_DLV_ERROR);
- }
- cu_context = attr->ar_cu_context;
-
- if (cu_context->cc_dbg == NULL) {
- _dwarf_error(NULL,error,DW_DLE_ATTR_DBG_NULL);
- return(DW_DLV_ERROR);
- }
- dbg = cu_context->cc_dbg;
-
- if (attr->ar_attribute_form == DW_FORM_string) {
-
- /* Check that string lies within current cu in .debug_info. */
- if ((attr->ar_debug_info_ptr + strlen(attr->ar_debug_info_ptr) + 1) >=
- (dbg->de_debug_info + cu_context->cc_debug_info_offset +
- cu_context->cc_length + dbg->de_length_size)) {
- _dwarf_error(dbg, error, DW_DLE_ATTR_FORM_SIZE_BAD);
- return(DW_DLV_ERROR);
- }
- *return_str = (attr->ar_debug_info_ptr);
- return DW_DLV_OK;
- }
-
- if (attr->ar_attribute_form == DW_FORM_strp) {
- READ_UNALIGNED(offset, attr->ar_debug_info_ptr, dbg->de_length_size);
-
- if (dbg->de_debug_str == NULL) {
- _dwarf_error(dbg, error, DW_DLE_DEBUG_STR_NULL);
- return(DW_DLV_ERROR);
- }
- *return_str = (dbg->de_debug_str + offset);
- return DW_DLV_OK;
- }
-
- _dwarf_error(dbg,error,DW_DLE_ATTR_FORM_BAD);
- return(DW_DLV_ERROR);
- }
-
-